<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../vue.js"></script>
</head>
<body>
    <div id="app">
        <h2>{{totalPrice}}</h2>
    </div>
    <script>
        const app=new Vue({
            el:'#app',
            data:{
                books:[
                    {id:110,name:'Unix艺术',price:119},
                    {id:111,name:'操作系统艺术',price:129},
                    {id:112,name:'Python艺术',price:139},
                    {id:113,name:'C++艺术',price:149},
                ]
            },
            computed:{
                totalPrice: function(){
                    let result=0
                    for (let i = 0; i < this.books.length; i++) {
                        result+=this.books[i].price
                    }
                    return result
                }
            }
        });
    </script>
</body>
</html>